package com.lemner.ke.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lemner.ke.R;
import com.lemner.ke.bean.RecommedBean;
import com.lemner.ke.bean.RecommendBean;
import com.lemner.ke.util.LoadImageUtils;

import org.w3c.dom.Text;

import java.util.List;

import static com.lemner.ke.base.URL.BASE_URL;

/**
 * 知 推荐 适配器
 * 库复用 这个适配器
 * @author raintea
 * @date 2018/9/20
 */
public class RecommendRecAdapter extends BaseQuickAdapter<RecommendBean,BaseViewHolder>{
    public RecommendRecAdapter(int layoutResId) {
        super(layoutResId);
    }

    public RecommendRecAdapter(int layoutResId, @Nullable List<RecommendBean> data) {
        super(layoutResId, data);
    }
    @Override
    protected void convert(BaseViewHolder helper, RecommendBean item) {
//        helper.setText(R.id.tv_title,item.getTitle());
        if (item!=null) {
            if (item.getCoverpath()!=null){
                String url = BASE_URL + item.getCoverpath();
                LoadImageUtils.loadRoundImage(url, (ImageView) helper.getView(R.id.iv_know_pic));
            }
            if (item.getType()!=null){
                helper.setText(R.id.tv_knowledge_type,item.getType());
            }
            if (item.getTitle()!=null){
                helper.setText(R.id.tv_knowledge_title,item.getTitle());
            }
            if (item.getHitnum()!=null){
                helper.setText(R.id.tv_knowledge_hit,item.getHitnum());
            }
            if (item.getLikesnum()!=null){
                helper.setText(R.id.tv_knowledge_like_num,item.getLikesnum());
            }
            String tags=item.getTags();
            if (tags != null) {
                String[] tagArray = tags.split(",");
                if (tagArray != null && tagArray.length > 0) {
                    for (int i = 0; i < tagArray.length; i++) {
                        if (i == 0) {
                            TextView text1 = helper.getView(R.id.tv_knowledge_tag1);
                            text1.setText(tagArray[i]);
                            text1.setVisibility(View.VISIBLE);
                        }
                        if (i == 1) {
                            TextView text2=helper.getView(R.id.tv_knowledge_tag2);
                            text2.setText(tagArray[i]);
                            text2.setVisibility(View.VISIBLE);
                        }
                    }
                }
            }

        }


    }

}
